<?php
error_reporting(0);
session_start();
header("Content-type: text/html; charset=utf-8");
include_once '../comm/config.php';
include_once '../comm/wjt.php';
include_once '../comm/checkpostandget.php';
$tag="center";
$apireg=APIREG;
$_SESSION["duoduouser"]=NULL;
$_SESSION['dduserid']=NULL;
$orther_web_id = authcode($_POST['orther_web_id'],'DECODE');
if($orther_web_id==''){
    exit('参数错误');
}
$orther_web_name = $_POST['orther_web_name'];
$orther_web=$_POST['orther_web'];
$sj = date("Y-m-d H:i:s");

if(!$orther_web_id || !$orther_web_name || !$orther_web){
    echo "缺少必要参数！";
	exit;
}

$sql="select a.Id,a.ddusername,a.dengji,a.ddpassword from ".$BIAOTOU."user as a,".$BIAOTOU."apilogin as b where a.Id=b.dduserid and b.ortheruserid='$orther_web_id' and b.ortherusername='$orther_web_name' and b.ortherwebname='$orther_web'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
if($row['Id']>0 and $row['ddusername']!=''){
	$q = "update " . $BIAOTOU . "user set loginnum=loginnum+1 ,lastlogintime='$sj' where ddusername='" . $row['ddusername'] . "'";
    mysql_query($q);
    $_SESSION["duoduouser"] = $row['ddusername'];
    $_SESSION["dduserid"] = $row['Id'];
    $_SESSION["dduserlevel"] = $row['dengji'];
	setcookie("ddusername", $row['ddusername'], time() + 1000 * 24 * 60 * 60, "/", SURL);
    setcookie("ddpassword", $row['ddpassword'], time() + 1000 * 24 * 60 * 60, "/", SURL);
	if(UC==1){
		include '../data/config.inc.php';
	    include '../uc_client/client.php';
	    echo $ucsynlogin = uc_user_synlogin($row['Id']); //同步登陆代码
	 }
    $windconfig = get_phpwind_config();
    if ($windconfig['open'] == 'on') {
        phpwind_login($row['ddusername'], $row['ddpassword'], false, $windconfig, 1);
        exit;
    }
	 
    echo "<script language=javascript>window.location='center.php';</script>";
    exit;
}

if (UC == 1) {
	include '../data/config.inc.php';
	include '../uc_client/client.php';

	/////////////////////////////////////
	$uc_name = iconv("utf-8", "utf-8", $orther_web_name);
	$uid = uc_user_checkname($uc_name);
	/////////////////////////////////////

	if ($uid<0) {
		$apireg=1; //用户名不合法 用户名存在 用户名包含不允许注册的词语，不允许直接注册，需要填写资料
	}
}
elseif(UC==0){
	$check=preg_match('/^[0-9a-zA-Z_\x{4e00}-\x{9fa5}]+$/u',$orther_web_name);

    $qz = "SELECT count(*) FROM " . $BIAOTOU . "user where ddusername='" . $orther_web_name . "'";
	$rs = mysql_query($qz);
	$t = mysql_fetch_array($rs);
	if ($t[0] > 0 or $check==0) {
		$apireg=1; //对不起，该用户名已经被注册，不允许直接注册，或者用户名包含非法字符，需要填写资料
	}
}
$_SESSION["yzm"]=rand(1000,9999);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册新用户 - <?php echo WEBTITLE?></title>
<link href="../css/usercss.css" rel="stylesheet" type="text/css">
<link href="../template/<?=MOBAN?>/css/common.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript">
$.ajaxSetup ({
    cache: false //关闭AJAX相应的缓存
});
regErr=new Array();
regErr[1]='恭喜，该用户名可以使用';
regErr[-1]='用户名不合法';
regErr[-2]='包含不允许注册的词语';
regErr[-3]='用户名已存在';

emailErr=new Array();
emailErr[1]='恭喜，该email可以使用';
emailErr[-1]='用户名不合法';
emailErr[2]='测试';
emailErr[-5]='email不允许注册';
emailErr[-6]='email已存在';
var ddName;
var ddPass;
var ddPass2;
var ddQq;
var ddEmail;
function checkUsername(name){
    if(getLength(name)<3 || getLength(name)>20){
		document.getElementById("ckuser").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>用户名长度必须为 3 - 20 位</font>';
		ddName=0;
	}
	else{
		var re = RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
		if (!re.test(name)){
			document.getElementById("ckuser").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>仅可使用汉字或数字字母和下划线</font>';
			ddName=0;
		}else{
			$.get('ckuser.php', 'name='+encodeURIComponent(name)+'&fresh=' + Math.random(), function(data){
				data=parseInt(data); 
				if(data<1) {
				document.getElementById("ckuser").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>'+regErr[data]+'</font>';
				ddName=0;
			    }else{
				    document.getElementById("ckuser").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900>'+regErr[data]+'</font>';
				    ddName=1;
			    }
		    });
		}
	}
}

function checkName(name){
		if(getLength(name)<3 || getLength(name)>20)
		{
			document.getElementById("ckname").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>用户名长度必须为 3 - 20 位</font>';
			ddUserName=0;
		}
		else
		{
			var re = RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
			if (!re.test(name)){
				document.getElementById("ckname").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>仅可使用汉字或数字字母和下划线</font>';
				ddUserName=0;
			}else{
			$.get('ckuser.php', 'name='+encodeURIComponent(name)+'&fresh=' + Math.random(), function(data){
				data=parseInt(data); 
				if(data<1) {
				document.getElementById("ckname").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900>该会员名存在</font>';
				ddUserName=1;
			  }else{
				  document.getElementById("ckname").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>该会员名不存在</font>';
				  ddUserName=0;
				  }
			});
			}
		}
}

function getLength(str) {
    var len = str.length;
    var reLen = 0;
    for (var i = 0; i < len; i++) {        
        if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
            // 全角    
            reLen += 2;
        } else {
            reLen++;
        }
    }
    return reLen;    
} 

function checkqq2(qq2)
{
    	if(getLength(qq2) <= 4)
		{
			document.getElementById("ckqq2").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>QQ号码应大于5位</font>';
			ddQq=0;
		}else
			{
				document.getElementById("ckqq2").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900>QQ号码正确</font>';
				ddQq=1;	
			}
}

function checkpass(password)
{
    	if(getLength(password)<6 || getLength(password)>20)
		{
			document.getElementById("ckpass").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>密码长度必须为 6 - 20 位</font>';
			ddPass=0;
		}
		else
		{
			document.getElementById("ckpass").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900>密码填写正确</font>';
			ddPass=1;
			
		}
}    

function checkpass2()
{
    	if(getLength(document.getElementById("password_check").value)<6 || getLength(document.getElementById("password_check").value)>20)
		{
			document.getElementById("ckpass2").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>密码长度必须为 6 - 20 位</font>';
			ddPass2=0;
		}
		else if (document.getElementById("password").value!=document.getElementById("password_check").value)
		{
			document.getElementById("ckpass2").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>两次密码输入不一致！</font>';
			ddPass2=0;
		}
		else
		{
			document.getElementById("ckpass2").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900>密码再次确认正确</font>';
			ddPass2=1;
		}
}    
function checkemail()
{
		var str = document.getElementById("email2").value;    
        if(str.length!=0)
		{    
			reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;    
			if(!reg.test(str))
			{    
				document.getElementById("ckemail").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>邮件格式填写错误</font>';
				ddEmail=0;
			}
			else
			{
				$.get('ckemail.php', 'email='+encodeURIComponent(str)+'&fresh=' + Math.random(), function(data){
				    data=parseInt(data); 
					if(data<1) {
			            document.getElementById("ckemail").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>'+emailErr[data]+'</font>';
						ddEmail=0;
		            }else{
			            document.getElementById("ckemail").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900>'+emailErr[data]+'</font>';
						ddEmail=1;
			        }
				});
			}
		}
		else
		{
				document.getElementById("ckemail").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>请填写电子邮件</font>';
				ddEmail=0;
		}
} 
function checkyzm()
{
	var yzm = document.getElementById("yzm").value;
    	if(getLength(yzm)!=4)
		{
			document.getElementById("ckyzm").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>验证码填写错误</font>';
			ddYzm=0;
		}
		else
		{
			document.getElementById("ckyzm").innerHTML = '请填写验证码';
			ddYzm=1;
			
		}
} 
function checkall()
{
	checkUsername($('#username').val());
	checkpass($('#password').val());
	checkpass2();
	checkqq2(document.getElementById('qq2').value);
	checkemail();
    checkyzm();
	if(ddName==0||ddPass==0||ddPass2==0||ddEmail==0||ddYzm==0||!document.getElementById("sm").checked)
	{
		alert('请填写完注册内容！');
		return false;
	}
	else
	{
		return true;
	}
}
$(function(){
    $('.title ul li a').click(function(){
	    $('.title ul li a').removeClass('current');
		$(this).addClass('current');
		$('table').hide();
		$('#'+$(this).attr('value')).show();
	});
})
</script>
</head>

<body>
<?php
include("../template/".MOBAN."/header.tpl.php");
?>
<?php
include("../template/".MOBAN."/nav.tpl.php");
?>
<div id="maincenter">
	<div id="maincenterleft">
		  <div style=" margin-bottom:5px;font-size:14px; color:#009900">您已经使用
<?=$orther_web?>账号登陆<?=WEBNICK?>！第一次登陆请按以下提示操作！</div>
<div class="title" style="width:445px; margin-bottom:15px; height:30px">
            <ul>
              <li><a value="complate" style="MARGIN-LEFT: 10px" <?php if($apireg==0){?> href="savereg.php?apireg=<?=urlencode(authcode('auto','ENCODE'))?>&orther_web=<?=urlencode($orther_web)?>&orther_web_id=<?=urlencode($orther_web_id)?>&orther_web_name=<?=urlencode($orther_web_name)?>&api=1&yzm=<?=$_SESSION['yzm']?>" <?php }?>>创建新账号</a></li>
              <li><a value="binding" class="current" style="MARGIN-LEFT: 10px">账号绑定</a></li>
            </ul>
          </div>
          <form id="form" name="form" method="post" action="savereg.php" onsubmit="return checkall()">
<input type="hidden" name="orther_web" value="<?=$orther_web?>" />
<input type="hidden" name="orther_web_id" value="<?=$orther_web_id?>" />
<input type="hidden" name="orther_web_name" value="<?=$orther_web_name?>" />
	  <table id="complate" width="480" border="0" align="left" cellpadding="0" cellspacing="0" bordercolorlight="#9acd32" hight="100" name="zhuce" style="font-size:14px; display:none">
		<tr>
		  <td width="18%" height="35" align="right" class="altbg1 STYLE2">&nbsp;&nbsp;用户名 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="username" type="text" onblur="checkUsername(this.value);" value="<?=$orther_web_name?>"  size="20" maxlength="20" style="width:130px;" id="username" class="ddinput" />
		  </span>
          </td>
		  <td width="51%" height="35" id="ckuser">用户名长度3-20位字母或数字</td>
		</tr>
        <script>
        checkUsername('<?=$orther_web_name?>');
        </script>
		<tr>
		  <td height="35" align="right" class="altbg1 STYLE2">密&nbsp;&nbsp;&nbsp;&nbsp;码 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="password" type="password" id="password"  onblur="checkpass(this.value);" size="20" maxlength="20" style="width:130px;" class="ddinput"/>
		  </span></td>
		  <td width="51%" height="35" id="ckpass">仅本站使用的密码</td>
		</tr>
		<tr>
		  <td height="35" align="right" class="altbg1 STYLE2">确认密码 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="password2" type="password" id="password_check" onblur="checkpass2();"  size="20" maxlength="20" style="width:130px;" class="ddinput"/>
		  </span></td>
		  <td width="51%" height="35" id="ckpass2">请再次确认密码</td>
		</tr>
		<tr>
		  <td height="35" align="right" class="altbg1 STYLE2">QQ号码 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="qq" type="text" id="qq2" onblur="checkqq2(document.getElementById('qq2').value);" onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" size="20" maxlength="50" style="width:130px;" class="ddinput"/>
		  </span></td>
		  <td width="51%" height="35" id="ckqq2">以便客服及时联系您</td>
		</tr>
		<tr>
		  <td height="35" align="right" class="altbg1 STYLE2">电子邮箱 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="email" type="text" id="email2" onblur="checkemail();"  size="20" maxlength="50" style="width:130px;" class="ddinput"/>
		  </span></td>
		  <td width="51%" height="35" id="ckemail">请务必填写正确，取回密码用</td>
		</tr>
        <tr>
		  <td height="35" align="right" class="altbg1 STYLE2">验 证 码 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="yzm" type="text" id="yzm" onblur="checkyzm();"  size="6" maxlength="4" style="width:50px;" class="ddinput"/>
		  </span>&nbsp;&nbsp;<img style="cursor:pointer" src="../comm/yzm.php" border="0" align="absmiddle" onclick="this.src='../comm/yzm.php?a='+Math.random()"/></td>
		  <td width="51%" height="35" id="ckyzm">请填写验证码</td>
		</tr>
		<tr>
		  <td height="35" align="right" class="altbg1 STYLE2">&nbsp;</td>
		  <td width="5%" height="35" colspan="3"><span class="STYLE2">
		    <input name="sm" id="sm" type="checkbox" value="checkbox" checked="checked" />我已经阅读过并同意声明
		  </span></td>
	    </tr>
		<tr>
		  <td height="35" align="right" class="altbg1">&nbsp;</td>
		  <td height="35" colspan="2"><input type="submit" name="Submit" value="创建" class="ddbutton" /></td>
		  <td width="51%" height="35"></td>
		</tr>
	  </table><input name="api" type="hidden" value="1" />
      </form>
      <form id="form" name="form" method="post" action="binding.php" onsubmit="">
<input type="hidden" name="orther_web" value="<?=$orther_web?>" />
<input type="hidden" name="orther_web_id" value="<?=$orther_web_id?>" />
<input type="hidden" name="orther_web_name" value="<?=$orther_web_name?>" />
      <table id="binding" width="480" border="0" align="left" cellpadding="0" cellspacing="0" bordercolorlight="#9acd32" hight="100" name="zhuce" style="font-size:14px;">
		<tr>
        <tr style="font-size:14px; height:20px;color:#009900">如果您已经注册过<?=WEBNICK?>！可绑定<?=WEBNICK?>和<?=$orther_web?>帐户
      </tr>
		  <td width="18%" height="35" align="right" class="altbg1 STYLE2">&nbsp;&nbsp;用户名 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="name" type="text" onblur="checkName(this.value);" value=""  size="20" maxlength="20" style="width:130px;" id="name" class="ddinput" />
		  </span></td>
		  <td width="51%" height="35" id="ckname"></td>
		</tr>
		<tr>
		  <td height="35" align="right" class="altbg1 STYLE2">密&nbsp;&nbsp;&nbsp;&nbsp;码 *&nbsp;&nbsp;</td>
		  <td height="35" colspan="2"><span class="STYLE2">
		    <input name="pwd" type="password" id="password" size="20" maxlength="20" style="width:130px;" class="ddinput"/>
		  </span></td>
		  <td width="51%" height="35" id=""></td>
		</tr>
		<tr>
		  <td height="35" align="right" class="altbg1">&nbsp;</td>
		  <td height="35" colspan="2"><input type="submit" name="Submit" value="绑定账号" class="ddbutton" /></td>
		  <td width="51%" height="35"></td>
		</tr>
	  </table>
      </form>
	</div>
	<div id="maincenterright" style="line-height:25px;">
	<b class="bigredtext">&nbsp;&nbsp;本站声明文件：</b><br />
&nbsp;&nbsp;1、所有提供的所有商品均通过淘宝网（www.taobao.com）进行交易，本网站只提供相关的链接和推广，所以不承担商品的质量及售后服务；<br />
&nbsp;&nbsp;2、本站不涉及网络支付等问题，所有商品购买最终都通过淘宝网及支付宝平台，故不存在账号泄露等问题，请买家放心；<br />
&nbsp;&nbsp;3、所有通过本站购买商品的买家均可获得一定现金金额的返还，该现金来自<?php echo WEBTITLE ?>帮助淘宝推广的佣金，所以能保证返还部分的兑现；<br />
&nbsp;&nbsp;4、当您在本站的账户金额达到10元以上的可以申请提现，由于淘宝每月的结算日期安排在20日前后，所以本站提现请求将在每月的20日准时发放，请大家查收。
<br />
<strong></strong>最后，<?php echo WEBTITLE ?>祝大家购物愉快！</span><br />
	</div>
	<div class="clear"></div>
</div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
?>
</body>
</html>